﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using LunwenYun.Tool.Configration;

namespace LunwenYun.Portal.WebLogic
{
    public class SiteBaseController : Controller
    {
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var requestPath  = filterContext.HttpContext.Request.Path;
            requestPath = requestPath == "/"?"/home/index":requestPath;
            var seoSetting = SiteResource.SeoSettings;
            var defaultTitle = seoSetting["default"]["title"];
            var defaultKeyWords = seoSetting["default"]["keywords"];
            var defaultDescription = seoSetting["default"]["description"];
            if (seoSetting.Keys.Contains(requestPath))
            {
                if (seoSetting[requestPath].Keys.Contains("title"))
                {
                    ViewBag.Title = seoSetting[requestPath]["title"];
                }
                else
                {
                    ViewBag.Title = defaultTitle;
                }
                if (seoSetting[requestPath].Keys.Contains("keywords"))
                {
                    ViewBag.Keywords = seoSetting[requestPath]["keywords"];
                }
                else
                {
                    ViewBag.Keywords = defaultKeyWords;
                }
                if (seoSetting[requestPath].Keys.Contains("description"))
                {
                    ViewBag.Description = seoSetting[requestPath]["description"];
                }
                else
                {
                    ViewBag.Description = defaultDescription;
                }
            }
            else
            {
                ViewBag.Title = defaultTitle;
                ViewBag.Keywords = defaultKeyWords;
                ViewBag.Description = defaultDescription;
            }
        }
    }
}
